//动态移动
function control(obj, attr, speed, long, callback) {
    clearInterval(obj.timer);
    if (parseInt(getStyle(obj, attr)) < long)
        speed = Math.abs(speed);
    else
        speed = -Math.abs(speed);

    document.onkeydown = function (event) { //加速！
        event = event || window.event;
        if (event.ctrlKey) {
            if (speed > 0)
                speed += 2;
            else
                speed -= 2;
        }
    }
    obj.timer = setInterval(function () {
        now = getStyle(obj, attr);

        var nuu = parseInt(now) + speed;

        if (speed > 0 && nuu >= long || speed < 0 && nuu <= long) {
            nuu = long;
        }

        obj.style[attr] = nuu + "px";
        if (nuu == long) {
            callback && callback();
            clearInterval(obj.timer);
        }
    }, 30);
}
//获取样式信息
function getStyle(obj, name) {
    if (window.getComputedStyle) {
        return getComputedStyle(obj, null)[name];
    } else {
        return obj.currentStyle[name];
    }
}
function realSysTime(clock){ 
   var now = new Date(); 
   var year = now.getFullYear();
   var month = now.getMonth();
   var date = now.getDate();
   var day = now.getDay();
   var hour = now.getHours();
   var minu = now.getMinutes();
   var sec = now.getSeconds();
   if(Number(sec) < 10){
	   sec = "0" + sec.toString();
   }
   month = month + 1; 
   var arr_week = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"); 
   var week = arr_week[day]; 
   var time = year + "年" + month + "月" + date + "日 " + week + " " + hour + ":" + minu + ":" + sec; //组合系统时间 
   clock.innerHTML = time;
} 

//自动切换
function moveToFunction(style, obj, flag){
	var stu = document.getElementsByClassName("welcome")[0];
	if(style == "none" && flag){
		obj.style.display = "block";
		stu.style.display = "none";
		previous = obj;
		return 1;
	}else if(flag){
		obj.style.display = "none";
		stu.style.display = "block";
		previous = obj;
		return 0;
	}else if(style == "none" && !flag){
		obj.style.display = "block";
		return 1;
	}else if(!flag){
		obj.style.display = "none";
		return 0;
	}
}
// 控件展示或隐藏书与搜索页面
function close(){
	var shower = document.getElementsByClassName("topSearch");
	var submit = document.getElementById("checkSubmit");
	var bnt = document.getElementById("insertInfo");
	var bnt1 = document.getElementById("insertInfoStyle");
	var bntL = document.getElementById("dropInfoStyle");
	var bntk = document.getElementById("changeMonney");
	var mn = document.getElementById("table");
	if(mn != null){
		mn.style.display = "none";
	}
//	var bnth = document.getElementsByClassName("serchToInfo")[0];
//	bnth.style.display = "none";
	bntk.style.display = "none";
	bntL.style.display = "none";
	bnt1.style.display = "none";
	bnt.style.display = "none";
	submit.style.display = "none";
	shower[0].style.display = "none";
}
function showBrrow(){
	close();
	var shower = document.getElementsByClassName("topSearch");
	var shower1 = document.getElementsByClassName("forBox");
	shower[0].style.display = "block";
	if(shower1 != null){
		for(var i = 0; i < shower1.length; i++){
			shower1[i].style.display = "block";
		}
	}
}
function closeBrrow(){
	close();
	var shower1 = document.getElementsByClassName("forBox");
	if(shower1 != null)
	for(var i = 0; i < shower1.length; i++){
		shower1[i].style.display = "none";
	}
}
function showNormal(){
	close();
	var shower1 = document.getElementsByClassName("forBox");
	if(shower1 != null)
	for(var i = 0; i < shower1.length; i++){
		shower1[i].style.display = "block";
	}
}
var flag = -1;
var previous = null;
window.onload = function(){
	window.setInterval("realSysTime(clock)",1000);
	var logos =  document.getElementsByClassName("topRight");
	var exit = document.getElementsByClassName("topLeft");
	var timer = setInterval(function () {
		var clock = document.getElementById("time");
	  	var now = new Date(); 
		var year = now.getFullYear();
		var month = now.getMonth();
		var date = now.getDate();
		var day = now.getDay();
		var hour = now.getHours();
		var minu = now.getMinutes();
		var sec = now.getSeconds();
		if(Number(sec) < 10){
		   sec = "0" + sec.toString();
		}
		month = month + 1; 
		var arr_week = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"); 
		var week = arr_week[day]; 
		var time = year + "年" + month + "月" + date + "日 " + week + " " + hour + ":" + minu + ":" + sec;
		clock.innerHTML = time;
	}, 1000);
	logos[0].onclick = function(){
		var container = document.getElementsByClassName("extendContain");
		var func1 = document.getElementsByClassName("functionToUserInfo");
		var func2 = document.getElementsByClassName("functionToBorrowing");
		var func3 = document.getElementsByClassName("functionToHotBook");
		var func4 = document.getElementsByClassName("functionToRight");
		var toFlag = 0;
		//控件功能集
		var style = container[0].style.display;
		moveToFunction(style, container[0], 0);
		flag = -1;
		previous = null;
		func1[0].onclick = function(){
			closeBrrow();
			var bnt1 = document.getElementsByClassName("extendInfo");
			style = bnt1[0].style.display;
			if(flag == 1 && previous != bnt1[0] && previous != null && !toFlag){
				moveToFunction(previous.style.display, previous);
			}
			flag = moveToFunction(style, bnt1[0], 1);
			toFlag = 0;
		}
		func2[0].onclick = function(){
			closeBrrow();
			var bnt1 = document.getElementsByClassName("extendBook");
			style = bnt1[0].style.display;
			if(flag == 1 && previous != bnt1[0] && previous != null && !toFlag){
				moveToFunction(previous.style.display, previous);
			}
			flag = moveToFunction(style, bnt1[0], 1);
			toFlag = 0;
		}
		func3[0].onclick = function(){
			closeBrrow();
			var bnt1 = document.getElementsByClassName("extendHot");
			style = bnt1[0].style.display;
			if(flag == 1 && previous != bnt1[0] && previous != null && !toFlag){
				moveToFunction(previous.style.display, previous);
			}
			flag = moveToFunction(style, bnt1[0], 1);
			toFlag = 0;
		}
		func4[0].onclick = function(){
			closeBrrow();
			var bnt1 = document.getElementsByClassName("extendRight");
			style = bnt1[0].style.display;
			if(flag == 1 && previous != bnt1[0] && previous != null && !toFlag){
				moveToFunction(previous.style.display, previous);
			}
			flag = moveToFunction(style, bnt1[0], 1);
			toFlag = 0;
		}
	}
	exit[0].onclick = function(){
		var exition = confirm("确定退出");
		if(exition == true){
			alert("退出成功");
			window.location.href = "index.jsp";
		}else{
			return;
		}
	}
	logos[0].click();
}